package com.steakliu.sun.disuse;

import com.steakliu.sun.common.util.RandomUtil;
import com.steakliu.sun.disuse.api.ConnectionsInfo;
import com.steakliu.sun.disuse.api.DisuseStrategy;
import com.steakliu.sun.spi.annotation.Join;

import java.util.List;

/**
 * 功能说明： 随机
 * <p>
 * Original @Author: steakliu-刘牌, 2023-02-07  00:11
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
@Join
public class RandomDisuseStrategy implements DisuseStrategy {
    @Override
    public ConnectionsInfo selectConnection(List<ConnectionsInfo> connectionsInfoList) {
        if (connectionsInfoList.isEmpty()){
            return null;
        }
        int size = connectionsInfoList.size();
        int index = RandomUtil.random(size);
        return connectionsInfoList.get(index);
    }
}
